<?php
/**
 * Created by IntelliJ IDEA.
 * User: yvdedu.com
 * Date: 2017/3/30
 * Time: 14:53
 */

namespace Blog\Controller;
use Common\Controller\AdminbaseController;


class IndexorderController extends AdminbaseController
{
    function Order(){//客户订单

        $where = array();
        $request = I('request.');
        $dd_id = I('request.dd_id');

        if (!empty($request['dd_id'])) {
            $where['id'] = intval($request['dd_id']);
        }

        if (!empty($request['keyword'])) {
            $keyword = $request['keyword'];
            $keyword_complex = array();
            $keyword_complex['dd_id'] = array('like',"%$keyword%");
            $keyword_complex['Customername'] = array('like', "%$keyword%");
            $keyword_complex['number'] = array('like', "%$keyword%");
            $keyword_complex['CityLocation'] = array('like', "%$keyword%");
            $keyword_complex['province'] = array('like',"%$keyword%");
            $keyword_complex['city'] = array('like',"%$keyword%");
            $keyword_complex['_logic'] = 'or';
            $where['_complex'] = $keyword_complex;
        }
        if ($dd_id){
            $where['dd_id'] = array('like',"%$dd_id%");
        }

        $users_model = M("order");

        $count = $users_model->where($where)->count();
        $page = $this->page($count, 20);

        $list = $users_model
            ->where($where)
            ->limit($page->firstRow . ',' . $page->listRows)
            ->select();
        $this->assign('list', $list);
        $this->assign("page", $page->show('Admin'));

        $this->display();
    }
    
    function addorder(){
        $Customername = I('Customername');
        $number = I('number');
        $CityLocation = I('CityLocation');
        $province = I('province');
        $city = I('city');
        var_dump($Customername);

        if (!empty($Customername)) {
            $cmf_order = M("order");
            $xt = $cmf_order->find();
            if (empty($xt)) {
                $this->ajaxReturn(333);
            } else {
                if (!empty($Customername) && !empty($CityLocation) && !empty($number) && !empty($province) && !empty($city)) {
                    $data['Customername'] = $Customername;
                    $data['CityLocation'] = $CityLocation;
                    $data['number'] = $number;
                    $data['province'] = $province;
                    $data['city'] = $city;
                    var_dump($data);
                    if (!empty($data)) {
                        $cmf_order->add($data);
                        $this->success("添加成功");
                    }
                } else {
                    $this->error("添加失败");
                }
            }
        }
    }
    function Odelete()
    {
        $id = I('id');
        if (!empty($id)) {
            $cmf_user = M("order");
            $cmf_user->where("dd_id=$id")->delete();
            $this->success("删除成功");
        } else {
            $this->error("删除失败");
        }
    }
}